package cn.caojun.auth.controller;

import cn.caojun.auth.annotation.caojunPermission;
import cn.caojun.auth.domain.Permission;
import cn.caojun.auth.query.PermissionQuery;
import cn.caojun.auth.service.IPermissionScanService;
import cn.caojun.auth.service.IPermissionService;
import cn.caojun.basic.utils.AjaxResult;
import cn.caojun.basic.utils.PageList;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
@Api(value = "权限管理",description = "权限管理的描述")
@caojunPermission(name = "权限管理",desc = "管理权限 ")
public class PermissionController {
    @Autowired
    IPermissionService permissionService;

    @GetMapping
    public AjaxResult getAllPermission(){
        try{
            List<Permission> permissionList=permissionService.getAll();
            return AjaxResult.me().setObject(permissionList);
        }catch (Exception e){
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }

    @PostMapping
    @caojunPermission(name = "查看权限页面",desc = "查看权限页面 ")
    public AjaxResult getPermissionList(@RequestBody PermissionQuery permissionQuery){
        try{
            PageList<Permission> pageList=permissionService.getLimteList(permissionQuery);
            return AjaxResult.me().setObject(pageList);
        }catch (Exception e){
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }



    @GetMapping("/tree")
    @caojunPermission(name = "修改权限管理的权限",desc = "修改权限管理的权限 ")
    public AjaxResult getPermissionTree(){
        try{
            List<Permission> permissionList=permissionService.getPermissionTree();
            return AjaxResult.me().setObject(permissionList);
        }catch (Exception e){
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }
}
